package com.allenyuan.gui;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import javax.swing.JTextArea;
import java.awt.Insets;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionListener;

import javax.swing.JButton;

public abstract class AbstractPanel extends JPanel implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8003651982863868680L;
	
	private static final String nextCommand = "下一步";
	private static final String lastCommand = "上一步";
	private static final String cancelCommand = "取  消";
	
	protected JPanel optionPanel;
	
	protected JButton lastButton;
	
	protected JButton nextButton;
	
	protected JButton cancelButton;
	
	private GuiContext context;
	
	protected GuiContext getContext() {
		return context;
	}
	/**
	 * Create the panel.
	 */
	public AbstractPanel(GuiContext context) {
		super();
		this.context = context; 
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 25, 0, 25, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 10, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel guideTitleText = new JLabel(getGuideTitle());
		guideTitleText.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		GridBagConstraints gbc_guideTitleText = new GridBagConstraints();
		gbc_guideTitleText.gridwidth = 5;
		gbc_guideTitleText.anchor = GridBagConstraints.WEST;
		gbc_guideTitleText.insets = new Insets(0, 0, 5, 0);
		gbc_guideTitleText.gridx = 1;
		gbc_guideTitleText.gridy = 0;
		add(guideTitleText, gbc_guideTitleText);
		
		JTextArea guideText = new JTextArea();
		guideText.setBackground(SystemColor.control);
		guideText.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		guideText.setEnabled(false);
		guideText.setEditable(false);
		guideText.setLineWrap(true);
		guideText.setDisabledTextColor(Color.black);
		guideText.setText(getGuideText());

		GridBagConstraints gbc_guideText = new GridBagConstraints();
		gbc_guideText.gridwidth = 5;
		gbc_guideText.insets = new Insets(0, 0, 5, 0);
		gbc_guideText.fill = GridBagConstraints.BOTH;
		gbc_guideText.gridx = 1;
		gbc_guideText.gridy = 1;
		add(guideText, gbc_guideText);
		
		optionPanel = new JPanel();
		GridBagConstraints gbc_optionPanel = new GridBagConstraints();
		gbc_optionPanel.gridwidth = 5;
		gbc_optionPanel.insets = new Insets(0, 0, 5, 0);
		gbc_optionPanel.fill = GridBagConstraints.BOTH;
		gbc_optionPanel.gridx = 1;
		gbc_optionPanel.gridy = 2;
		add(optionPanel, gbc_optionPanel);
		GridBagLayout gbl_optionPanel = new GridBagLayout();
		gbl_optionPanel.columnWidths = new int[]{0};
		gbl_optionPanel.rowHeights = new int[]{0};
		gbl_optionPanel.columnWeights = new double[]{Double.MIN_VALUE};
		gbl_optionPanel.rowWeights = new double[]{Double.MIN_VALUE};
		optionPanel.setLayout(gbl_optionPanel);
		
		lastButton = new JButton(lastCommand);
		lastButton.setActionCommand("last");
		lastButton.addActionListener(this);
		GridBagConstraints gbc_lastButton = new GridBagConstraints();
		gbc_lastButton.insets = new Insets(0, 0, 0, 5);
		gbc_lastButton.gridx = 1;
		gbc_lastButton.gridy = 4;
		add(lastButton, gbc_lastButton);
		
		nextButton = new JButton(nextCommand);
		nextButton.setActionCommand("next");
		nextButton.addActionListener(this);
		GridBagConstraints gbc_nextButton = new GridBagConstraints();
		gbc_nextButton.insets = new Insets(0, 0, 0, 5);
		gbc_nextButton.gridx = 3;
		gbc_nextButton.gridy = 4;
		add(nextButton, gbc_nextButton);
		
		cancelButton = new JButton(cancelCommand);
		cancelButton.setActionCommand("cancel");
		cancelButton.addActionListener(this);
		GridBagConstraints gbc_cancelButton = new GridBagConstraints();
		gbc_cancelButton.gridx = 5;
		gbc_cancelButton.gridy = 4;
		add(cancelButton, gbc_cancelButton);

	}
	
	
	protected abstract String getGuideText();
	
	protected abstract String getGuideTitle();

}
